package com.lazyboyl.big.data.read.service;

import com.lazyboyl.big.data.read.handle.IHandle;
import com.lazyboyl.big.data.read.util.BigFileReader;
import com.lazyboyl.big.data.read.util.RedisCache;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author linzf
 * @since 2021-08-02
 * 类描述：超大文本数据读取的实现
 */
@Service
public class BigDataReadService {

    @Resource
    private RedisCache redisCache;

    /**
     * 功能描述： 模拟实现擦好大文件的解析
     *
     * @return 返回处理结果
     */
    public Map<String, Object> readBigData() {
        Map<String, Object> result = new HashMap<>(2);
        // 此处大家替换成自己的相关文件即可。
        BigFileReader bigFileReader = new BigFileReader(new File("E:\\learn-work\\fantastic-ideas\\big-data-read-handle\\big-data-read\\bigData\\bigTxt.txt"), new IHandle() {
            @Override
            public void readLine(String line) {
                // 采用redis的生产者和消费者模式来进行数据的快速读取，此处大家也可改造成mq等的实现
                redisCache.lPush("BIG-DATA-READ", line);
            }
        }, "UTF-8", 1024 * 1024, 8);
        bigFileReader.singleStart();
        result.put("msg", "请求处理完成");
        result.put("code", 200);
        return result;
    }

}
